package com.tarry.observer.jdk;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Objects;
import java.util.Observable;

/**
 * 发布者-被观察者
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class Publisher extends Observable {

    private String msg;

    public void setMsg(String msg){
        // 当数据发生修改时，赋值修改状态，并同志观察者
        if (!Objects.equals(this.msg,msg)) {
           this.msg = msg;
           super.setChanged();
        }
        super.notifyObservers();
    }
}
